package org.xwb.future;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class FutureTaskDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer> futureTask = new FutureTask<>(() -> {
            Thread.sleep(2000);
            return 1;
        });
        new Thread(futureTask).start();

        // 获取结果阻塞 main 线程
        System.out.println(futureTask.get());
        System.out.println("main线程");

    }
}
